package demo;

import java.util.LinkedList;
import java.util.Queue;

class MyStack {

    private Queue<Integer> queue1 = new LinkedList<>();

    public MyStack() {

    }

    public void push(int x) {
        queue1.add(x);
    }

    public int pop() {
        if (queue1.isEmpty()) {
            return -1;
        }
        int size = queue1.size();
        while (size > 1) {
            queue1.add(queue1.poll());
            size--;
        }
        int result = queue1.poll();
        queue1.add(result);
        return result;
    }

    public int top() {
        if (queue1.isEmpty()) {
            return -1;
        }
        int size = queue1.size();
        while (size > 1) {
            queue1.add(queue1.poll());
            size--;
        }
        return queue1.peek();
    }

    public boolean empty() {
        return queue1.isEmpty();
    }
}

/**
 * Your MyStack object will be instantiated and called as such:
 * MyStack obj = new MyStack();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.top();
 * boolean param_4 = obj.empty();
 */